﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Xinkui.WebModel.BasicControl;
using CommonFramework.Utility;
using Xinkui.DataAccess.AutoGenerator;
using Xinkui.Common;
using Xinkui.Entity.AutoGenerator;
using Xinkui.WebModel;
using Xinkui.WebModel.Helper;

public partial class UserControl_UserCenter_Seller_UC_PostCertificate : AccountControl {
    public int Edit {
        get {
            return WebHelper.GetQueryStringValue<int>("e", 0);
        }
    }

    public string ImageLogo { get; set; }

    protected void Page_Load(object sender, EventArgs e) {
        if (!IsPostBack) {
            var cerInfo = Singleton<CompanyCertificateMaintainDataAccess>.Instance.CompanyCertificateMaintain_View(Edit);
            if (cerInfo != null && cerInfo.IsDeleted == 0 && cerInfo.CompanyID == this.BasePage.CurrentLogin.CompanyID) {
                this.txtCerticicationName.Text = cerInfo.CertName;
                this.txtDescription.Text = cerInfo.Remark;
                
                ImageLogo = Xinkui.Common.FileUpload.GetDirectoryPath(cerInfo.PicPath, Xinkui.Common.Enum.ESourceType.FromCertification);
            }
        }
    }


    protected void btnSubmit_Click(object o, EventArgs e) {

        CompanyCertificateMaintain_Entity entity = new CompanyCertificateMaintain_Entity();
        entity.IsDeleted = 0;
        DateTime n = DateTime.Now;
        entity.CreateDate = n;
        entity.AuditDate = n;
        entity.AuditStatus = (int)AuditStatusEnum.New;
        entity.UpdateDate = n;
        string image = WebHelper.GetFormValue<string>("hidfilepath");

        if (Edit > 0) {
            entity = Singleton<CompanyCertificateMaintainDataAccess>.Instance.CompanyCertificateMaintain_View(Edit);
            if (entity == null || entity.CompanyID != this.BasePage.CurrentLogin.CompanyID) {
                UIHelper.ShowErrorTips("The certification infomation has error");
                return;
            }
            entity.UpdateDate = n;
            
            entity.AuditStatus = (int)AuditStatusEnum.Change;
        }
        if (!string.IsNullOrEmpty(image))
            entity.PicPath = image;
        ImageLogo = Xinkui.Common.FileUpload.GetDirectoryPath(entity.PicPath, Xinkui.Common.Enum.ESourceType.FromCertification);
        entity.CompanyID = this.BasePage.CurrentLogin.CompanyID;
        entity.Remark = this.txtDescription.Text;
        entity.CertName = this.txtCerticicationName.Text;
        if (Edit > 0) {
            Singleton<CompanyCertificateMaintainDataAccess>.Instance.CompanyCertificateMaintain_Update(entity);
        }
        else {
            Singleton<CompanyCertificateMaintainDataAccess>.Instance.CompanyCertificateMaintain_Add(entity);
        }

        //UIHelper.ShowSuucessTips("Certification Info Saved", URLHelper.LinkToCertificate());
    }
}